<?php

namespace App\Nova;

use App\Nova\Repeater\VideoItem;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Image;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Repeater;
use Laravel\Nova\Fields\Tag;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Panel;

class Video extends Resource
{
    public static string $model = \App\Models\Video::class;

    public static $title = 'title';

    public static $search = [
        'title',
    ];

    public static function label(): string
    {
        return '视频';
    }

    public function fields(NovaRequest $request): array
    {
        return [
            ID::make()->sortable(),

            Text::make('标题', 'title')->rules('required'),

            Textarea::make('简介', 'description'),

            Text::make('索引', 'abbr')->onlyOnDetail(),

            Image::make('缩略图', 'picture')->prunable()->creationRules('required'),

            Repeater::make('视频', 'videos')
                ->repeatables([
                    VideoItem::make(),
                ])
                ->asJson()
                ->rules('required'),

            Boolean::make('显示', 'show')->default(true),

            Boolean::make('仅VIP观看', 'vip'),

            Number::make('播放次数', 'playback')->min(0),

            Number::make('点赞数', 'like')->min(0),

            Number::make('评分', 'score')->min(0)->max(5),

            new Panel('SEO', new SeoFields),

            Number::make('访问次数', 'visits')->exceptOnForms(),

            Tag::make('演员', 'actors', Actor::class)->displayAsList(),

            Tag::make('分类', 'categories', Category::class),

            Tag::make('专题', 'specials', Special::class),

            Tag::make('类型', 'tags', \App\Nova\Tag::class),

            DateTime::make('生成时间', 'created_at')->onlyOnDetail(),
            DateTime::make('更新时间', 'updated_at')->onlyOnDetail(),
        ];
    }
}
